﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace WFIM.Framework.Extensions
{
    public static class StreamExtension
    {
        public static int Write(this System.IO.Stream targetStream,System.IO.Stream fromStream)
        {
            int result = 0;
            byte[] buffer = new byte[4096];
            fromStream.Seek(0, SeekOrigin.Begin);
            int readLength = fromStream.Read(buffer,0,buffer.Length);

            while (readLength >0)
            {
                result += readLength;
                targetStream.Write(buffer, 0, readLength);
                readLength = fromStream.Read(buffer,0,buffer.Length);
            }

            return readLength;
        }

        public static int Write(this System.Net.Sockets.NetworkStream target, Stream fromStream)
        {
            return Write((Stream)target, fromStream);
        }
    }
}
